home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 24
/
Amiga Format AFCD24 (Feb 1998, Issue 108).iso
/
-seriously_amiga-
/
shareware
/
programming
/
other
/
apic
/
examples
/
dimmer.lst
< prev
next >
Wrap
File List
|
1998-01-05
|
20KB
|
403 lines
#PIC V1.0 (c)1997 J.Petroglou LIST FILE
#file: dh2:IDE/APICforAMINET/APIC/examples/dimmer.asm
#date: Sun Dec 14 20:42:11 1997
#pic : PIC16C84
#xtal: 4000000 Hz
ADDR CODE SRCLINE SOURCECODE
0000 000001
0000 000002 ;
0000 000003 ; pic 4 dummies..
0000 000004 ; This is a phase first slicer for the 16C84 - documented in broken inglisch ;-(
0000 000005 ; assemble me with: picasm dimm.asm <CR>
0000 000006 ; $VER: dimmer.asm V1.42 (19.09.97)
0000 000007 ; ©: This program is free software and can be used and distributed
0000 000008 ; ©: under the terms of the GNU General Public License.
0000 000009 ;
0000 000010
0000 000011
0000 000012 list p=PIC16C84, r=dec, s=on
0000 000013 ; ^interpret the code as case sensItive
0000 000014 ; ^radix is decimal
0000 000015 ; ^the `84 is the target processor
0000 000016
0000 000017
0000 000018
0000 000019 device hs_osc,protect_off,wdt_off
0000 000020 ; ^the watchdog sleeps ;-)
0000 000021 ; ^no read protection
0000 000022 ; ^config the osilator in high-speed mode
0000 000023
0000 000024
0000 000025
0000 000026 XTAL 4000000 ;crystal freq. for Amiga Picsim [Hz]
0000 000027
#include 'ram:p16c84.inc' start
0000 000001 ;==========================================================================
0000 000002 ;
0000 000003 ; Register Definitions
0000 000004 ;
0000 000005 ;==========================================================================
0000 000006
0000 000007 W EQU H'0000'
0000 000008 F EQU H'0001'
0000 000009
0000 000010 ;----- Register Files------------------------------------------------------
0000 000011
0000 000012 INDF EQU H'0000'
0000 000013 TMR0 EQU H'0001'
0000 000014 PCL EQU H'0002'
0000 000015 STATUS EQU H'0003'
0000 000016 FSR EQU H'0004'
0000 000017 PORTA EQU H'0005'
0000 000018 PORTB EQU H'0006'
0000 000019 EEDATA EQU H'0008'
0000 000020 EEADR EQU H'0009'
0000 000021 PCLATH EQU H'000A'
0000 000022 INTCON EQU H'000B'
0000 000023
0000 000024 OPTION_REG EQU H'0081'
0000 000025 TRISA EQU H'0085'
0000 000026 TRISB EQU H'0086'
0000 000027 EECON1 EQU H'0088'
0000 000028 EECON2 EQU H'0089'
0000 000029
0000 000030 ;----- STATUS Bits --------------------------------------------------------
0000 000031
0000 000032 IRP EQU H'0007'
0000 000033 RP1 EQU H'0006'
0000 000034 RP0 EQU H'0005'
0000 000035 NOT_TO EQU H'0004'
0000 000036 NOT_PD EQU H'0003'
0000 000037 Z EQU H'0002'
0000 000038 DC EQU H'0001'
0000 000039 C EQU H'0000'
0000 000040
0000 000041 ;----- INTCON Bits --------------------------------------------------------
0000 000042
0000 000043 GIE EQU H'0007'
0000 000044 EEIE EQU H'0006'
0000 000045 T0IE EQU H'0005'
0000 000046 INTE EQU H'0004'
0000 000047 RBIE EQU H'0003'
0000 000048 T0IF EQU H'0002'
0000 000049 INTF EQU H'0001'
0000 000050 RBIF EQU H'0000'
0000 000051
0000 000052 ;----- OPTION Bits --------------------------------------------------------
0000 000053
0000 000054 NOT_RBPU EQU H'0007'
0000 000055 INTEDG EQU H'0006'
0000 000056 T0CS EQU H'0005'
0000 000057 T0SE EQU H'0004'
0000 000058 PSA EQU H'0003'
0000 000059 PS2 EQU H'0002'
0000 000060 PS1 EQU H'0001'
0000 000061 PS0 EQU H'0000'
0000 000062
0000 000063 ;----- EECON1 Bits --------------------------------------------------------
0000 000064
0000 000065 EEIF EQU H'0004'
0000 000066 WRERR EQU H'0003'
0000 000067 WREN EQU H'0002'
0000 000068 WR EQU H'0001'
0000 000069 RD EQU H'0000'
0000 000070
0000 000071 ;==========================================================================
0000 000072 ;
0000 000073 ; RAM Definition
0000 000074 ;
0000 000075 ;==========================================================================
0000 000076
0000 000077 ; __MAXRAM H'AF'
0000 000078 ; __BADRAM H'07', H'30'-H'7F', H'87'
0000 000079
0000 000080 ;==========================================================================
0000 000081 ;
0000 000082 ; Configuration Bits
0000 000083 ;
0000 000084 ;==========================================================================
0000 000085
0000 000086 _CP_ON EQU H'3FEF'
0000 000087 _CP_OFF EQU H'3FFF'
0000 000088 _PWRTE_ON EQU H'3FFF'
0000 000089 _PWRTE_OFF EQU H'3FF7'
0000 000090 _WDT_ON EQU H'3FFF'
0000 000091 _WDT_OFF EQU H'3FFB'
0000 000092 _LP_OSC EQU H'3FFC'
0000 000093 _XT_OSC EQU H'3FFD'
0000 000094 _HS_OSC EQU H'3FFE'
0000 000095 _RC_OSC EQU H'3FFF'
0000 000096
0000 000097 LIST
#include end.
0000 000029
0000 000030
0000 000031 ;some definitions ...
0000 000032
0000 000033 #define ELR PORTA,2 ; led-triac modul (via 470R)
0000 000034 #define POWER_LINE PORTA,3 ; 100V - 250V AC (via 2 * 4M7 in series !)
0000 000035 ; W A R N I N G !¡! HIGH VOLTAGE !!!
0000 000036
0000 000037
0000 000038 #define DARKER PORTB,4 ; connect this pin to ground to make it darker
0000 000039 #define BRIGHTER PORTB,5 ; connect this pin to ground to make it brighter
0000 000040
0000 000041 ; these are the definitions work in MY circuit (230V 50Hz)
0000 000042
0000 000043 #define IGNITION_DELAY 30 ; the led of the power modul must be on for at least
0000 000044 ; some µ seconds
0000 000045 #define IGNITION_PRESET 128 ; about 90° first slice
0000 000046 #define DIMM_MIN 15 ;max. value off the fileregister dimm
0000 000047
0000 000048
0000 000049 DIMM_MAX = 200 ; min. value off the fileregister dimm
0000 000050 DIMM_X = 254 ; min. value off the fileregister dimm
0000 000051
0000 000052 XTAL = 4000000 ;crystal freq. for delay-time calulations [Hz]
0000 000053 LINE_FREQ = 50 ;power_line freq. [Hz]
0000 000054
0000 000055 CLOCKCYCLES_PER_INSTRUCTIONS = 4
0000 000056
0000 000057 IPHW = XTAL/CLOCKCYCLES_PER_INSTRUCTIONS/LINE_FREQ/2
0000 000058
0000 000059 ; IPHW = Instruction Per HalvWave( i.e. 10ms @ 50Hz)
0000 000060
0000 000061
0000 000062 INSTRUCTIONCYCLES_PER_DELAYCYC = 3
0000 000063
0000 000064 ;DIMM_WAIT = ((IPHW-50)/DIMM_MAX+20)/ INSTRUCTIONCYCLES_PER_DELAYCYC
0000 000065 DIMM_WAIT = (IPHW-122-DIMM_X*8)/ (INSTRUCTIONCYCLES_PER_DELAYCYC * DIMM_X)
0000 000066
0000 000067
0000 000068 ; some very simple macros..
0000 000069
0000 000070 macro elr_off
0000 000071 bcf ELR ; LED of the powermodul off
0000 000072 endm
0000 000073
0000 000074 macro elr_on
0000 000075 bsf ELR ; LED of the powermodul on
0000 000076 endm
0000 000077
0000 000078
0000 000080 CBLOCK 0xc
0000 000081 dimm
0000 000082 dimm_counter
0000 000083 wait_counter
0000 000084 ENDC
0000 000085
0000 000086
0000 000087
0000 000088 org 0x0 ; the program starts at 0x0000
0000 000089
0000 000091
0000 0185 000092 clrf PORTA ; clear both ports
0001 0186 000093 clrf PORTB
0002 000094
0002 1683 000095 bsf STATUS, RP0 ; switch to bank 1
0003 000096
0003 1381 000097 bcf OPTION_REG, 7 ; PORTB pull-ups are enabled (for the 2 keys)
0004 000099
0004 3000 000100 movlw 0x0
0005 0086 000101 movwf TRISB
0006 0085 000102 movwf TRISA
0007 1585 000104 bsf POWER_LINE ; these pins are inputs (in=1, out=0)
0008 1606 000105 bsf DARKER
0009 1686 000106 bsf BRIGHTER
000A 000107
000A 1283 000108 bcf STATUS, RP0 ; switch back to bank 0
000B 000109
000B 000110
000B 3080 000111 movlw IGNITION_PRESET
000C 008C 000112 movwf dimm
000D 000113
000D 000114
000D 000115 main_loop
000D 2030 000116 call wait_line_change ; call a subroutine
000E 080C 000117 movf dimm,w ; transfer the the data form the "dimm" file-register
000F 201D 000119 call dimm_it
0010 1E86 000120 btfss BRIGHTER ; test if the BRIGHTER pin is low
0011 0A8C 000121 incf dimm ; ok, it`s low, increment dimm by one
0012 1E06 000122 btfss DARKER ; test if the DARKER pin is low
0013 038C 000123 decf dimm ; ok, it`s low, decrement dimm by one
0014 000124
0014 300F 000125 movlw DIMM_MIN ; move DIMM_MIN in the working register
0015 020C 000126 subwf dimm,w ; subtract w from dimm and store the result in w
0016 1903 000127 btfsc STATUS, Z ; is last result Zero ?
0017 0A8C 000128 incf dimm ; yes -> inc. dimm
0018 000129
0018 30C8 000130 movlw DIMM_MAX ; same with the upper limit...
0019 020C 000131 subwf dimm,w
001A 1903 000132 btfsc STATUS, Z
001B 038C 000133 decf dimm ; ...but here we decrease dimm
001C 000134
001C 280D 000135 goto main_loop ; jump to main_loop and repeat this stuff forever...
001D 000136
001D 000137
001D 000138 dimm_it
001D 008D 000139 movwf dimm_counter ; copy w in dimm_counter
001E 098D 000140 comf dimm_counter,f ; generate the complement of dimm_counter and
001F 000142 dimm_loop
001F 2026 000143 call wait
0020 0B8D 000144 decfsz dimm_counter
0021 281F 000145 goto dimm_loop
0022 1505 000146 bsf ELR ; LED of the powermodul on
0023 202B 000147 call ignition_wait ; wait some µ seconds
0024 1105 000148 bcf ELR ; LED of the powermodul off
0025 0008 000149 return
0026 000150
0026 300A 000152 movlw DIMM_WAIT
0027 008E 000153 movwf wait_counter
0028 000154 wait_loop
0028 0B8E 000155 decfsz wait_counter
0029 2828 000156 goto wait_loop
002A 0008 000157 return
002B 000158
002B 000159
002B 301E 000161 movlw IGNITION_DELAY
002C 008E 000162 movwf wait_counter
002D 000163 i_wait_loop
002D 0B8E 000164 decfsz wait_counter
002E 282D 000165 goto i_wait_loop
002F 0008 000166 return
0030 000167
0030 000168
0030 1D85 000170 btfss POWER_LINE
0031 2835 000171 goto line_is_low
0032 000172 line_is_high
0032 1985 000173 btfsc POWER_LINE
0033 2832 000174 goto line_is_high
0034 0008 000175 return ;return from subroutine
0035 000176 line_is_low
0035 1D85 000177 btfss POWER_LINE
0036 2835 000178 goto line_is_low
0037 0008 000179 return
0038 000180
0038 000181
0038 000182
0038 000233
0038 000234
Used Symbols
-----------------------------------------
W 00000000
F 00000001
INDF 00000000
TMR0 00000001
PCL 00000002
STATUS 00000003
FSR 00000004
PORTA 00000005
PORTB 00000006
EEDATA 00000008
EEADR 00000009
PCLATH 0000000A
INTCON 0000000B
OPTION_REG 00000081
TRISA 00000085
TRISB 00000086
EECON1 00000088
EECON2 00000089
IRP 00000007
RP1 00000006
RP0 00000005
NOT_TO 00000004
NOT_PD 00000003
Z 00000002
DC 00000001
C 00000000
GIE 00000007
EEIE 00000006
T0IE 00000005
INTE 00000004
RBIE 00000003
T0IF 00000002
INTF 00000001
RBIF 00000000
NOT_RBPU 00000007
INTEDG 00000006
T0CS 00000005
T0SE 00000004
PSA 00000003
PS2 00000002
PS1 00000001
PS0 00000000
EEIF 00000004
WRERR 00000003
WREN 00000002
WR 00000001
RD 00000000
_CP_ON 00003FEF
_CP_OFF 00003FFF
_PWRTE_ON 00003FFF
_PWRTE_OFF 00003FF7
_WDT_ON 00003FFF
_WDT_OFF 00003FFB
_LP_OSC 00003FFC
_XT_OSC 00003FFD
_HS_OSC 00003FFE
_RC_OSC 00003FFF
DIMM_MAX 000000C8
DIMM_X 000000FE
XTAL 003D0900
LINE_FREQ 00000032
CLOCKCYCLES_PER_INSTRUCTIONS 00000004
IPHW 00002710
INSTRUCTIONCYCLES_PER_DELAYCYC 00000003
DIMM_WAIT 0000000A
dimm 0000000C
dimm_counter 0000000D
wait_counter 0000000E
init 00000000
main_loop 0000000D
dimm_it 0000001D
dimm_loop 0000001F
wait 00000026
wait_loop 00000028
ignition_wait 0000002B
i_wait_loop 0000002D
wait_line_change 00000030
line_is_high 00000032
line_is_low 00000035
Used Defines
-----------------------------------------
IGNITION_PRESET 128
POWER_LINE PORTA,3
DARKER PORTB,4
BRIGHTER PORTB,5
ELR PORTA,2
DIMM_MIN 15
IGNITION_DELAY 30
PROGRAM MEMORY USAGE TABLE: '-' = not used 'X' = used
0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXX--------
0040 : ---------------- ---------------- ---------------- ----------------
0080 : ---------------- ---------------- ---------------- ----------------
00C0 : ---------------- ---------------- ---------------- ----------------
0100 : ---------------- ---------------- ---------------- ----------------
0140 : ---------------- ---------------- ---------------- ----------------
0180 : ---------------- ---------------- ---------------- ----------------
01C0 : ---------------- ---------------- ---------------- ----------------
0200 : ---------------- ---------------- ---------------- ----------------
0240 : ---------------- ---------------- ---------------- ----------------
0280 : ---------------- ---------------- ---------------- ----------------
02C0 : ---------------- ---------------- ---------------- ----------------
0300 : ---------------- ---------------- ---------------- ----------------
0340 : ---------------- ---------------- ---------------- ----------------
0380 : ---------------- ---------------- ---------------- ----------------
03C0 : ---------------- ---------------- ---------------- ----------------
Program Memory Words Used: 0056
Program Memory Words Free: 0968
Errors: 0